package com.kmzx.one.project.controller;

import com.kmzx.one.common.utils.MyAssert;
import com.kmzx.one.project.net.BaseResult;
import com.kmzx.one.project.service.UserLicenseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Project one
 * @Author: carol
 * @Date: 2020/9/4-15:19
 */
@Api(tags = "快美甄选_[ 用户协议_接口 ]")
@RestController
public class UserLicenseController extends BaseController {


    @Autowired
    UserLicenseService userLicenseService;

    @ApiOperation(value = "1.检测用户是否读过协议", notes = "1.检测用户是否读过协议",position = -1)
    @GetMapping(value = "license/has")
    public BaseResult checkUserLicenseRead(String userId) {
        try {
            MyAssert.notNullObject(userId, "userId 为null");
            int has = userLicenseService.checkHasUserLicense(userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(has);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "2.用户读取消息", notes = "2.用户读取消息")
    @GetMapping(value = "license/read")
    public BaseResult readUserLicense(String userId) {
        try {
            MyAssert.notNullObject(userId, "userId 为null");
            userLicenseService.insertUserLicense(userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(200);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

}
